package user;

import java.util.Iterator;
import java.util.List;

import com.jidesoft.*;
import net.sf.*;
import net.sf.json.*;
import com.jidesoft.*;
import groovy.*;
import groovyjarjarantlr.*;
import javax.servlet.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.*;
import jsyntaxpane.*;
import nu.xom.*;
import org.apache.*;
import org.codehaus.*;
import org.hamcrest.*;
import org.jdesktop.*;
import org.junit.*;
import org.mortbay.*;
import org.mortbay.log.Log;
import org.w3c.*;
import org.xml.*;
import com.atlassian.*;
import com.atlassian.crowd.exception.ApplicationPermissionException;
import com.atlassian.crowd.exception.CrowdException;
import com.atlassian.crowd.exception.InvalidAuthenticationException;
import com.atlassian.crowd.exception.OperationFailedException;
import com.atlassian.crowd.exception.UserNotFoundException;
import com.atlassian.crowd.integration.rest.service.factory.RestCrowdClientFactory;
import com.atlassian.crowd.service.client.CrowdClient;
import com.atlassian.crowd.model.group.Group;
import com.atlassian.crowd.model.group.Membership;
import com.atlassian.crowd.model.user.*;
import com.atlassian.crowd.service.client.*;
import com.atlassian.crowd.integration.authentication.*;
import org.apache.log4j.*;  
import com.atlassian.crowd.model.user.User;
import com.atlassian.crowd.integration.http.CrowdHttpAuthenticator;

@SuppressWarnings("unused")

public class ConnectTest {

	public String  ConnectTest(){
		String appLink = "https://code.bestbuy.com/crowd/";
		String conStatus = "Success"; 
		CrowdClient prof2 = new RestCrowdClientFactory().newInstance(appLink,"profile-mgt","1nitialPa55");
		try {

			System.out.println("Connection testing ....." + "\n"); 

			prof2.testConnection();

			conStatus = "************Connection SUCCESSFULL ! <&" + "\n"; 
		} catch (OperationFailedException e) {
			conStatus = "FAIL ! <&"; 
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidAuthenticationException e) {
			System.out.println("App Invalid Authentication Please check APP password");
			conStatus = "FAIL ! <&"; 
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ApplicationPermissionException e) {
			System.out.println("Application persmission issues. See Below ");
			// TODO Auto-generated catch block
			e.printStackTrace();
			conStatus = "FAIL ! <&"; 
		}
		System.out.println( "\n" + conStatus );

		return  conStatus;

	}




	/*public static void main(String[] args) throws UserNotFoundException, CrowdException, ApplicationPermissionException, ParserConfigurationException {
		String appLink = "https://code.bestbuy.com/crowd/";

		CrowdClient prof2 = new RestCrowdClientFactory().newInstance(appLink,"profile-mgt","1nitialPa55");
		 prof2.testConnection();

		String name = "testprofile1";
		 System.out.println( "\n" + "First Name: " + prof2.getUser(name).getFirstName() + "\n" + "Display Name: " + 
				 prof2.getUser(name).getDisplayName() + "\n"	+ "Email: "  +
				 prof2.getUser(name).getEmailAddress()
				 + "\n");

		 System.out.println( "\n" + "GROUPPPP *********** " + prof2.getGroup("Browse Widening (Team)").getName()  + "\n");

		 Group gr = null;
		prof2.addGroup(gr);


		 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		 DocumentBuilder db = dbf.newDocumentBuilder();

		 //Document doc = db.parse(prof2.testConnection());

		 PasswordCredential pass = null;
		// User  testREST = "Done";

		 //prof2.addUser(testREST, null);




		List  member =  prof2.getGroupsForUser(name, 0, -1);

		member.get(2);
	 */


}
